

#include "../../common/message.hpp"
#include "../../common/net.hpp"
#include "../../common/dispatcher.hpp"
#include "../../common/muduobase/include/muduo/base/Logging.h"
#include "../../server/rpc_router.hpp"
#include "../../server/rpc_server.hpp"
#include <vector>
bool Add(const Json::Value &req, Json::Value &res)
{
    int int_a = req["nums1"].asInt(), int_b = req["nums2"].asInt();
    int ret = int_a + int_b;
    res["ret"] = ret;
    return true;
}

//当前是提供服务的服务器，端口9090，连接注册中心8080
int main()
{
    // 取消muduo库的普通日志
    muduo::Logger::setLogLevel(muduo::Logger::FATAL);

    // 1、创建一个方法
    RPC::Server::SDFactory::Ptr sfactory = std::make_shared<RPC::Server::SDFactory>();
    sfactory->setCallback(Add);
    sfactory->setMethod("Add");
    std::vector<RPC::Server::ServiceDiscribe::ParamsDescribe> params;
    params.push_back({"nums1", RPC::Server::VType::INTEGRAL});
    params.push_back({"nums2", RPC::Server::VType::INTEGRAL});
    sfactory->setParamsDescribe(params);
    sfactory->setReturnType(RPC::Server::VType::BOOL);
    RPC::Server::ServiceDiscribe::Ptr service1 = sfactory->build();

    // 2、创建一个server
    RPC::Server::RpcServer server(RPC::Address("127.0.0.1", 9090), true, RPC::Address("127.0.0.1", 8080));

    // 3、注册方法
    server.registerMethod(service1);
    server.start();
    return 0;
}